import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:test01/okhttp_test/page/pages/tabbarview_test.dart';

import 'weight_page.dart';

/*
*
*
* 登录界面------------登录欢迎
*
*
* */


class UserNamePage extends StatefulWidget {
  UserNamePage({Key key,this.nicknames,this.picurl}) : super(key: key);
  String nicknames;
  var picurl;

  @override
  _UserNamePageState createState() => _UserNamePageState();
}

class _UserNamePageState extends State<UserNamePage> {
  GlobalKey globalKey=GlobalKey();




  @override
  void initState() {
    super.initState();
    // WidgetsBinding.instance.addPostFrameCallback((callback) {
    //   RenderBox renderBox = globalKey.currentContext.findRenderObject();
    //   if(renderBox.size.height > 30){
    //     widget.nicknames=widget.nicknames.???;
    //   }
    // });
  }


  @override
  Widget build(BuildContext context) {

    ///昵称长度判断
      String mm="欢迎回来${widget.nicknames}，登录成功！";
      if(mm.length*23>(MediaQuery.of(context).size.width-82)){
        String xx=widget.nicknames.substring(widget.nicknames.length-((((mm.length*23)-(MediaQuery.of(context).size.width-82).toInt())/23).ceil())-1);
        widget.nicknames=widget.nicknames.replaceAll(xx, "...");
        mm="欢迎回来${widget.nicknames}，登录成功！";
        setState(() {
        });
      }


    return Scaffold(
      appBar: AppBar(
        actions:<Widget>[GestureDetector(
          onTap: (){
            ///跳转界面并关闭当前页面
            Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) => TabBarViewPage()),
                  (route) => route == null,
            );
          },
          child:Container(
            alignment: Alignment.center,
            margin: EdgeInsets.only(right: 16),
            child: Text("跳过",style: TextStyle(fontSize: 15,color: Color.fromRGBO(51, 51, 51, 1)),),
          )
        ),],
        backgroundColor: Colors.white,
        elevation: 0,
        automaticallyImplyLeading: true,
      ),
      body: Container(
        margin: EdgeInsets.only(left: 41,right: 41),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
          Container(
          width: 60,
          height: 60,
          margin: EdgeInsets.only(top: 148),
          decoration: BoxDecoration(
            image: DecorationImage(
                fit: BoxFit.cover,
                image: FileImage(widget.picurl),
            ),
            borderRadius: BorderRadius.all(Radius.circular(60.0)),
          ),
          ),
            Container(
              key: globalKey,
              margin: EdgeInsets.only(top: 9),
              child: Text("${mm}",style: TextStyle(fontSize: 23,color: Color.fromRGBO(17, 17, 17, 1)),),
            ),
            Container(
              margin: EdgeInsets.only(top: 12),
              child: Text("为了确保让你获得出色的体验，我们需要对你做出进一步的了解",style: TextStyle(fontSize: 14,color: Color.fromRGBO(51, 51, 51, 1)),),
            ),
            GestureDetector(
              onTap: (){
                Navigator.push(context, MaterialPageRoute(builder: (context) => IndexWeightPage()),
                );
              },
              child: Container(
                width: MediaQuery.of(context).size.width-82,
                height: 44,
                alignment: Alignment.center,
                margin: EdgeInsets.only(top:27.5),
                decoration:BoxDecoration(
                  color: Color.fromRGBO(17, 17, 17, 1),
                  borderRadius:BorderRadius.circular((3.0)), // 圆角度
                ),
                child: Text("立即开始",style: TextStyle(fontSize: 16,color: Color.fromRGBO(255, 255, 255, 1)),),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
